package com.djinfo.work.controller;

import com.alibaba.fastjson.support.odps.udf.CodecCheck;
import com.djinfo.work.common.bean.AjaxJson;
import com.djinfo.work.common.util.StringUtil;
import com.djinfo.work.entity.QsQuestionEntity;
import com.djinfo.work.entity.QsTitleEntity;
import com.djinfo.work.service.QsQuestionService;
import com.djinfo.work.service.QsTitleService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;

/**
 * Created by admin on 2017/6/9.
 */
@Controller
@RequestMapping("/QsTitle")
public class QsTitleController {

    private static final Log log = LogFactory.getLog(QsTitleController.class);
    @Autowired
    private QsTitleService qsTitleService;
    @Autowired
    private QsQuestionService questionService;
    /**
     * 标题列表
     */
    @RequestMapping("/list.do")
    @ResponseBody
    public AjaxJson list(QsTitleEntity qsTitleEntity, Integer pagenum, Integer pagesize){
        AjaxJson ajaxJson=new AjaxJson();
        ajaxJson=qsTitleService.getList(qsTitleEntity,pagenum,pagesize);
        return ajaxJson;
    }
    /**
     * 新增修改操作
     */
    @RequestMapping("/saveOrUpdate.do")
    @ResponseBody
    public AjaxJson addOrUpdate(QsTitleEntity qsTitleEntity, HttpServletRequest request){
        AjaxJson ajaxJson=new AjaxJson();
        ajaxJson=qsTitleService.saveOrUpdate(qsTitleEntity,request);
        return ajaxJson;

    }
    /**
     * 获取标题对象信息
     */
    @RequestMapping("/info.do")
    public ModelAndView info(QsTitleEntity qsTitleEntity){
        if(qsTitleEntity.getId()==null||"".equals(qsTitleEntity.getId())){
            qsTitleEntity=new QsTitleEntity();
        }else {
            qsTitleEntity = qsTitleService.getQsTitleById(qsTitleEntity.getId());
        }
        return new ModelAndView("title/edit.html","title",qsTitleEntity);
    }

    @RequestMapping("/getTitleListBySearch.do")
    @ResponseBody
    public AjaxJson getTitleListBySearch(QsTitleEntity qsTitleEntity){
        AjaxJson ajaxJson=new AjaxJson();
        ajaxJson=qsTitleService.getTitleListBySearch(qsTitleEntity);
        return ajaxJson;
    }
    @RequestMapping("/delete.do")
    @ResponseBody
    public AjaxJson delete(QsTitleEntity qsTitleEntity){
        AjaxJson ajaxJson=new AjaxJson();
        ajaxJson=qsTitleService.delete(qsTitleEntity);
        return ajaxJson;

    }

    @RequestMapping("/getQuestionList.do")
    @ResponseBody
    public AjaxJson getQuestionList(QsQuestionEntity qsQuestionEntity){
        AjaxJson ajaxJson=qsTitleService.getQuestionList(qsQuestionEntity);

        return ajaxJson;
    }










}
